package band.wukong.practice.java.pattern.dynamicproxy;

import java.lang.reflect.Proxy;

/**
 * Desc:
 * Author: sunjs
 * Date: 2009-12-9 11:13:34
 */
public class SimpleDynamicProxy {
    public static void consumer(Interface iface) {
        iface.doSth();
        iface.sthElse("malimalihong...");
    }

    public static void main(String[] args) {
        RealObject real = new RealObject();
        consumer(real);

        System.out.println("==============================");
        //Insert a proxy and call again
        Interface proxy = (Interface) Proxy.newProxyInstance(
                Interface.class.getClassLoader(),
                new Class[]{Interface.class},
                new DynamicProxyHandler(real)
        );

        consumer(proxy);

    }
}
